package com.yry.timertask.chapter31;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.TimerTask;

public class MyTimerTask extends TimerTask{
	private  String name;
	private Integer count = 0;

	public MyTimerTask(String name) {
		this.name = name;
	}

	@Override
	public void run() {
		if(count>=3){
			cancel();
			System.out.println("MyTimerTask cancel"+
					" &&  MyTimerTask cancel time is:"+ LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
		}else{
			/*打印当前name的内容*/
			System.out.println("MyTimerTask exec name is : "+name +
					" &&  MyTimerTask exec time is:"+ LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
			count++;
		}

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
